<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <title>服务创建</title>
    <base href=<%=basePath%>
          <%@include file="../common_css.jsp" %>
                  </head>
<body class="childrenBody">

<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="customer"
                           class="layui-input
					searchVal" placeholder="客户"/>
                </div>
                <div class="layui-input-inline">
                    <select name="type" id="type">
                        <option value="-1">请选择</option>
                    </select>
                </div>

                <a class="layui-btn search_btn" data-type="reload"><i
                        class="layui-icon">&#xe615;</i> 搜索</a>
            </div>
        </form>
    </blockquote>
    <table id="customerServeList" class="layui-table" lay-filter="customerServes"></table>


    <script type="text/html" id="toolbarDemo">
        <a class="layui-btn layui-btn-normal addNews_btn" lay-event="add">
            <i class="layui-icon">&#xe608;</i>
            添加
        </a>
    </script>
    <script id="saleChanceListBar" type="text/html">
        <a class="layui-btn layui-btn-xs" id="edit" lay-event="edit">详情</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" id="cancel" lay-event="cancel">取消</a>
    </script>

</form>
<script type="text/javascript">
    layui.use(['table', 'layer', "form"], function () {
        var layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            table = layui.table;

        //服务列表展示
        table.render({
            elem: '#customerServeList',
            url: 'cusDrive/findCusDriveNotHandle',
            cellMinWidth: 95,
            page: true,
            height: "full-125",
            limits: [10, 15, 20, 25],
            limit: 10,
            method: "post",
            toolbar: "#toolbarDemo",
            id: "customerServeListTable",
            cols: [[
                {field: "id", title: '编号', fixed: "true", width: 80},
                {
                    field: 'customerName', title: '客户名', minWidth: 50, align: "center", templet: function (d) {
                        return d.customer.name;
                    }
                },
                {field: 'driveName', title: '试驾人姓名', minWidth: 100, align: 'center'},
                {field: 'stringDriveType', title: '试驾类型', align: 'center'},
                {field: 'carSeries', title: '汽车型号', minWidth: 100, align: 'center'},
                {field: 'driveTime', title: '试驾时间', align: 'center', minWidth: 150},
                {field: 'createTime', title: '创建时间', align: 'center', minWidth: 150},
                {title: '操作', templet: '#saleChanceListBar', fixed: "right", align: "center", minWidth: 150}
            ]]
        });

        function openAddCustomerServeDialog() {
            var title = "服务管理-服务创建";
            var url = "cusDrive/toDriveAddPage";
            layui.layer.open({
                title: title,
                type: 2,
                area: ["700px", "500px"],
                maxmin: true,
                content: url
            })
        }
        $.post("dictionaries/findDriveType",function (res) {
            for(var i=0;i<res.length;i++) {
                $("#type").append("<option value=\"" + res[i].valueId + "\"   >" + res[i].valueName + "</option>");
            }
            // 重新渲染下拉框内容
            layui.form.render("select");
        });

        //多条件搜索
        $(".search_btn").on("click",function(){
            table.reload("customerServeListTable",{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    customerName: $("input[name='customer']").val(),  //客户名
                    driveType: $("#type").val()  //服务类型
                },
                url:'cusDrive/findCusDriveNotHandleConditional',
                contentType:"application/json"
            })
        });
        // 头工具栏事件
        table.on('toolbar(customerServes)', function (obj) {
            switch (obj.event) {
                case "add":
                    openAddCustomerServeDialog();
            }
        });
        //详情和取消
        table.on('tool(customerServes)', function (obj) {
            var layEvent = obj.event;
            console.log($(this).parent().parent().siblings(":first").children().text())
            console.log($(this))
            if (layEvent == 'edit') {
                var title = "服务管理-服务详情";
                var url = "cusDrive/toDriveAddPage?id=" + $(this).parent().parent().siblings(":first").children().text();
                layui.layer.open({
                    title: title,
                    type: 2,
                    area: ["700px", "400px"],
                    maxmin: true,
                    content: url
                })
            } else {
                $.post("cusDrive/cancel", {id: $(this).parent().parent().siblings(":first").children().text()}, function () {
                    location.reload()
                })
            }
        });

    });
</script>

</body>
</html>
